package zkk.com.mengqu.activity;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.media.Image;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import zkk.com.mengqu.R;
import zkk.com.mengqu.adapter.CircleFriendArticleListAdapter;
import zkk.com.mengqu.view.refresh.LoadMoreListView;

/**
 * Created by Administrator on 2017/4/5.
 * 饭友圈饭友发表的文章列表
 */
public class CircleFriendArticleListActivity extends Activity implements View.OnClickListener{
    private Context context;
    private ImageView ivBack , author , search;//返回，作者，搜索
    private LoadMoreListView listView;
    private SwipeRefreshLayout swipeRefreshLayout;
    private CircleFriendArticleListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_circle_friend_article_list);
        context = getApplicationContext();
        initView();
    }

    public void initView(){
        ivBack = (ImageView)findViewById(R.id.iv_back);
        author = (ImageView) findViewById(R.id.iv_author);
        search = (ImageView) findViewById(R.id.iv_search);
        listView=(LoadMoreListView)findViewById(R.id.lv_listView);
        swipeRefreshLayout=(SwipeRefreshLayout)findViewById(R.id.shelf_swipe_refresh);
        adapter = new CircleFriendArticleListAdapter(context);
        listView.setAdapter(adapter);

        swipeRefreshLayout.setColorSchemeColors(Color.GREEN, Color.RED, Color.YELLOW);
        swipeRefreshLayout.setEnabled(true);

        ivBack.setOnClickListener(this);
        author.setOnClickListener(this);
        search.setOnClickListener(this);

        listView.setOnLastItemVisibleListener(new LoadMoreListView.OnLastItemVisibleListener() {
            @Override
            public void onLastItemVisible() {
                Toast.makeText(context , "加载结束" , Toast.LENGTH_LONG).show();
            }
        });

        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                Toast.makeText(context , "刷新结束" , Toast.LENGTH_LONG).show();
                swipeRefreshLayout.setRefreshing(false);//
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_back:
                finish();
                break;
            case R.id.iv_author:
                Toast.makeText(context , "作者" , Toast.LENGTH_LONG).show();
                break;
            case R.id.iv_search:
                Toast.makeText(context , "搜索" , Toast.LENGTH_LONG).show();
                break;
            default:
                break;
        }
    }
}
